package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.Coupon;
import com.fz.service.CouponService;
import com.fz.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 存储优惠券信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @GetMapping("/getCouponByUid")
    public ResultVo<IPage<Coupon>> getCouponByUid(Long userId, Integer pageNo, Integer pageSize) {
        return ResultVo.success(couponService.getCouponsByUid(userId, pageNo, pageSize), "查询优惠券成功");
    }

    @PostMapping("/give")
    public ResultVo<Boolean> giveCouponToUser(Long userId, Long amount) {
        return ResultVo.success(couponService.giveCouponToUser(userId, amount));
    }

    @GetMapping("/user")
    public ResultVo<List<Coupon>> getCouponByUid(Long userId) {
        return ResultVo.success(couponService.getCouponsByUid(userId));
    }
}
